package com.sjy.mvvmdemo.roomdb.dbfactory

import com.sjy.mvvmdemo.roomdb.db.UserDao
import com.sjy.mvvmdemo.roomdb.db.UserEntity

/**
 * 封装的一层数据库操作类
 *
 * 用于关联viewModel,方便viewModel直接使用操作数据库
 */
class UserRepository(private val userDao: UserDao) {
    val userLists = userDao.getAllUserData()

    suspend fun insert(user: UserEntity): Long {
        return userDao.addUserData(user)
    }

    suspend fun update(user: UserEntity): Int {
        return userDao.updateUserData(user)
    }

    suspend fun delete(user: UserEntity): Int {
        return userDao.deletUser(user)
    }

    suspend fun deleteAll(): Int {
        return userDao.deleteAll()
    }
}